<?php
require('config.php');
require('emotion.json.php');
        $user_id=$_REQUEST['user_id'];
        $leixing=$_REQUEST['leixing'];
        $bt=$_REQUEST['bt'];
        $content=$_REQUEST['content'];
        $img_list=$_REQUEST['img_list'];
        $fanwei=$_REQUEST['fanwei'];
        $ps_way=$_REQUEST['ps_way'];
        $money=$_REQUEST['money'];
        $lat=$_REQUEST['lat'];
		$lon=$_REQUEST['lon'];
		$type=$_REQUEST['type'];
        $address=$_REQUEST['address'];
        $time=date('Y-m-d H:i:s');
        if($isEmotion==1)
        {
        	for($i=0;$i<count($emotion_json);$i++)
	        {
	        	$content=str_replace($emotion_json[$i]['text'],"<img src=\"../emotion/".$emotion_json[$i]['name'].".png\">",$content);
	        }
        }
        if($ps_way=="送货上门") $ps_way_num=0;
        else if($ps_way=="自取") $ps_way_num=1;
        else $ps_way_num=2;
        for($i=0;$i<count($emotion_json);$i++)
        {
        	$content=str_replace($emotion_json[$i]['text'],"\<img src=\"../emotion/".$emotion_json[$i]['name'].".png\"\>",$content);
        }
        $sql="select isWeibang from `".$oto."_users` where `userId`='{$user_id}' and userFlag='1'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$user_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($user_info))
		{
			if($user_info[0]['isWeibang']==0)
			{
				$data[0]['pan']="-1";
				$data[0]['msg']="没有权限发微帮";
				echo json_encode($data);
				die();
			}
		}
		$sql="select * from `".$oto."_help_cate` where `cateName`='{$leixing}'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$help_cate[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$cid=0;
		if(isset($help_cate))
		{
			$cid=$help_cate[0]['id'];
		}
		$sql="INSERT INTO ".$oto."_help (`cid`,`title`,`content`,`type`,`userId`,`address`,`lat`,`lon`,`range`,`money`,`delivery`,`img`,`createTime`) VALUES ('$cid','$bt','$content','$type','$user_id','$address','$lat','$lon','$fanwei','$money','$ps_way_num','$img_list','$time')";
        $result=$db->query($sql);
        if($result)
        {
        	$data[0]['pan']="true";
        }
        else $data[0]['pan']="false";
		echo json_encode($data);
?>